package com.why.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.why.pojo.Category;
import com.why.service.CategoryService;
import com.why.mapper.CategoryMapper;
import com.why.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @author 王-自信
* @description 针对表【category】的数据库操作Service实现
* @createDate 2024-11-26 16:12:56
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{

    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public void add(Category category) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        category.setCreateUser(id);
        category.setCreateTime(new Date());
        category.setUpdateTime(new Date());
        categoryMapper.insert(category);
    }

    @Override
    public Category getByCategoryName(String categoryName) {
        return categoryMapper.getByCategoryName(categoryName);
    }

    @Override
    public List<Category> listCategory() {
        return categoryMapper.selectList(null);
    }

    @Override
    public Category detail(String id) {
        return categoryMapper.selectById(id);
    }

    @Override
    public void updateCategory(Category category) {
        categoryMapper.updateCategory(category);
    }
}




